package org.rowingmanager.register
{
	import flash.events.Event;
	import flash.events.IOErrorEvent;
	import flash.net.*;
	
	import mx.controls.Alert;
	public class RegisterHandler
	{
		private static var REGISTER_ORG:String = "http://localhost:8080/RowingManagement/organization/register" ;
		
		public var org_title:String;  /* ORGANIZATION PROPERTIES   */
		public var org_taxid:String;
		public var org_phone:String;
		public var org_type:String;
		public var org_street:String;
		public var org_city:String;
		public var org_postalCode:String;
		public var org_state:String;
		public var org_country_id:String;
		
		public var email:String; 
		public var password:String;/* USER PROPERTIES*/
		
		private var urlReq:URLRequest;
		private var urlLoader:URLLoader;
		
		public function RegisterHandler()
		{
			
		}
		
		public function registerOrganization():void {
			
			urlReq = new URLRequest(REGISTER_ORG);
			urlReq.method = "POST";
			var params:URLVariables = new URLVariables();
			params.org_title = this.org_title;
			params.org_phone = this.org_phone;
			params.org_type = this.org_type;
			params.org_taxid = this.org_taxid;
			params.org_street = this.org_street;
			params.org_city = this.org_city;
			params.org_postalCode = this.org_postalCode;
			params.org_state = this.org_state;
			params.org_country_id = this.org_country_id;
			
			params.email = this.email;
			params.password = this.password;
			
			urlReq.data = params;
			urlLoader = new URLLoader(urlReq);
			urlLoader.dataFormat = URLLoaderDataFormat.TEXT;
			urlLoader.addEventListener(Event.COMPLETE, handleResponse);
			urlLoader.addEventListener(IOErrorEvent.IO_ERROR,handleIOError);
			urlLoader.load(urlReq);
		}
		
		private function handleResponse(e:Event):void{
			var response:String = urlLoader.data;
		    if(response.substr(0,7) == "Success"){
				mx.controls.Alert.show(response);
		    }
		    else
		    	mx.controls.Alert.show(response);
			
		}
		
		private function handleIOError(e:IOErrorEvent):void {
			mx.controls.Alert.show("IO Error happened "+ e.text);
		}

	}
}